﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Flame.Controls.Common
{
    public class InputPlugin : Attribute
    {
        public InputPlugin()
        {

        }
    }
    public static class InputPluginLoader
    {
        public static List<Type> LoadAll(string path)
        {
            List<Type> availableTypes = new List<Type>();
            if (!Directory.Exists(path)) return availableTypes;
            foreach (string f in Directory.EnumerateFiles(path, "*.dll"))
            {
                try
                {
                    var a = Assembly.LoadFrom(f);
                    foreach (Type t in a.GetTypes())
                    {
                        if (t.IsDefined(typeof(InputPlugin), false))
                            availableTypes.Add(t);
                    }
                }
                catch 
                {
                    FileInfo fi = new FileInfo(f);
                    string destfile = Flame.Dlr.PathsHelper.GetExePath(fi.Name);
                    if (!File.Exists(destfile)) File.Copy(f, destfile);
                }
            }
            return availableTypes;
        }
    }
}
